import 'package:dio/dio.dart%20';
import 'package:flutter/material.dart';
// import 'package:dio/dio.dart as MyDio';

/**
 * 网络请求  dio
 */
class DioHttpDemo extends StatelessWidget {
  const DioHttpDemo({super.key});

  /**
   *
   */
  void _getHttp() async {
    Dio dio = Dio();
    Response response = await dio.get('https://www.baidu.com/');
    print(response.data.toString());
  }

  /**
   * post
   */
  void _postHttp() async {
    Dio dio = Dio();
    FormData formData = FormData.fromMap({'name': 'kobe', 'age': 30});
    Response response = await dio.post('', data: formData);
    print(response.data.toString());
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'dio',
      home: Scaffold(
        appBar: AppBar(
          title: Text('dio demo'),
          centerTitle: true,
        ),
        body: ElevatedButton(onPressed: () {}, child: Text('dio请求网络数据')),
      ),
    );
  }
}
